﻿package lobby
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.text.TextField;
	import lobby.exchangeddata.HashTable;
	
	/**
	 * ...
	 * @author Nguyen Hoang Giang (Tom)
	 */
	public class HistoryPanelSedie extends HistoryPanelBase
	{
		public var result0:MovieClip;
		public var result1:MovieClip;
		public var result2:MovieClip;
		public var result3:MovieClip;
		public var result4:MovieClip;
		
		private static const RESULT_0:String = "0";
		private static const RESULT_1:String = "1";
		private static const RESULT_2:String = "2";
		private static const RESULT_3:String = "3";
		private static const RESULT_4:String = "4";
		
		public override function initBoard(resultArr:Array):void
		{
			removeHistory();
			if (resultArr.length == 0)
				return;
			
			var pos:uint = 0;
			var flagEven:Boolean;
			var flagTemp:Boolean;
			var flagCheckEvenOdd:Boolean;
			var tempHis:Array = new Array();
			tempHis = resultArr[0].split("-");
			if (tempHis[1] % 2 == 0)
			{
				flagEven = true;
			}
			else
			{
				flagEven = false;
			}
			var iconHis:MovieClip = attachIcon(tempHis[1]);
			iconHis.name = tempHis[0];
			for (var i:uint = 1; i < resultArr.length; i++)
			{
				tempHis = new Array();
				tempHis = resultArr[i].split("-");
				flagCheckEvenOdd = checkEvenOdd(tempHis[1]);
				if (flagEven)
				{
					if (flagCheckEvenOdd)
					{
						rowInd++;
						flagTemp = true;
					}
					else
					{
						colInd++;
						rowInd = 0;
						flagTemp = false;
					}
				}
				else
				{
					if (flagCheckEvenOdd)
					{
						colInd++;
						rowInd = 0;
						flagTemp = true;
					}
					else
					{
						rowInd++;
						flagTemp = false;
					}
				}
				if (rowInd == rowNum)
				{
					colInd++;
					rowInd = 0;
				}
				
				iconHis = attachIcon(tempHis[1]);
				iconHis.name = tempHis[0];
				iconHis.name = tempHis[0];
				flagEven = flagTemp;
			}
		
		}
		
		private function checkEvenOdd(value:uint):Boolean
		{
			if (value % 2 == 0)
				return true;
			return false;
		}
		
		public override function attachIcon(type:String):MovieClip
		{
			
			var hisIcon:MovieClip = MovieClip(new HistoryIconFt());
			hisIcon.result0.visible = false;
			hisIcon.result1.visible = false;
			hisIcon.result2.visible = false;
			hisIcon.result3.visible = false;
			hisIcon.result4.visible = false;
			
			hisBoard.addChild(hisIcon);
			hisIcon.x = colInd * 18.5;
			hisIcon.y = rowInd * 18.5;
			//hisIcon.scaleX = hisIcon.scaleY = 0.79;
			
			if (type == HistoryPanelSedie.RESULT_0)
			{
				hisIcon.result0.visible = true;
			}
			if (type == HistoryPanelSedie.RESULT_1)
			{
				hisIcon.result1.visible = true;
			}
			if (type == HistoryPanelSedie.RESULT_2)
			{
				hisIcon.result2.visible = true;
			}
			if (type == HistoryPanelSedie.RESULT_3)
			{
				hisIcon.result3.visible = true;
			}
			if (type == HistoryPanelSedie.RESULT_4)
			{
				hisIcon.result4.visible = true;
			}
			
			return hisIcon;
		}
	}

}